#include <string>
#include <stdio.h>
#include "HiDraw.h"
#include "hi_mapi_osd.h"

HiDraw::HiDraw()
{
}

HiDraw::~HiDraw()
{
}

HI_S32 HiDraw::StartDrawBox(HI_HANDLE osdHdl, DrawContent& boxContent)
{
    HI_S32 ret;
    HI_MAPI_OSD_ATTR_S osdAttr;
    osdAttr.u32DispNum = 1;
    osdAttr.astDispAttr[0].bShow = HI_TRUE;
    osdAttr.astDispAttr[0].enBindedMod = HI_MAPI_OSD_BINDMOD_VPROC;
    osdAttr.astDispAttr[0].ModHdl = boxContent.m_modHdl;
    osdAttr.astDispAttr[0].ChnHdl = boxContent.m_chnHdl;
    osdAttr.astDispAttr[0].u32FgAlpha = 128;
    osdAttr.astDispAttr[0].u32BgAlpha = 0;
    osdAttr.astDispAttr[0].enCoordinate = HI_MAPI_OSD_COORDINATE_ABS_COOR;
    osdAttr.astDispAttr[0].stStartPos.s32X = (HI_U32)boxContent.m_minX & (~1);;
    osdAttr.astDispAttr[0].stStartPos.s32Y = (HI_U32)boxContent.m_minY & (~1);
    osdAttr.astDispAttr[0].u32Batch = 0;
    osdAttr.stContent.enType = HI_MAPI_OSD_TYPE_CIRCLE;
    osdAttr.stContent.u32Color = boxContent.m_color;
    osdAttr.stContent.stCircleContent.u32Width = (HI_U32)((HI_FLOAT)(boxContent.m_maxX - boxContent.m_minX)) & (~1);
    osdAttr.stContent.stCircleContent.u32Height = (HI_U32)((HI_FLOAT)(boxContent.m_maxY - boxContent.m_minY)) & (~1);

    ret = HI_MAPI_OSD_SetAttr(osdHdl, &osdAttr);
    if(ret != HI_SUCCESS)
    {
        printf("HI_MAPI_OSD_SetAttr failed, osdHdl:%d \n", osdHdl);
        return ret;
    }

    printf("osd start:%d  \n", osdHdl);
    ret = HI_MAPI_OSD_Start(osdHdl);
    if(ret != HI_SUCCESS)
    {
        printf("HI_MAPI_OSD_Start failed, osdHdl:%d \n", osdHdl);
        return ret;
    }
    return HI_SUCCESS;

}


HI_S32 HiDraw::StartDrawText(HI_HANDLE osdHdl, DrawContent& textContent)
{
    HI_S32 ret;
    HI_MAPI_OSD_ATTR_S osdAttr;
    osdAttr.u32DispNum = 1;
    osdAttr.astDispAttr[0].bShow = HI_TRUE;
    osdAttr.astDispAttr[0].enBindedMod = HI_MAPI_OSD_BINDMOD_VPROC;
    osdAttr.astDispAttr[0].ModHdl = textContent.m_modHdl;
    osdAttr.astDispAttr[0].ChnHdl = textContent.m_chnHdl;
    osdAttr.astDispAttr[0].u32FgAlpha = 128;
    osdAttr.astDispAttr[0].u32BgAlpha = 0;
    osdAttr.astDispAttr[0].enCoordinate = HI_MAPI_OSD_COORDINATE_ABS_COOR;
    osdAttr.astDispAttr[0].stStartPos.s32X = (HI_U32)textContent.m_minX& (~1);;
    osdAttr.astDispAttr[0].stStartPos.s32Y = (HI_U32)textContent.m_minY & (~1);
    osdAttr.astDispAttr[0].u32Batch = 0;
    osdAttr.stContent.enType = HI_MAPI_OSD_TYPE_STRING;
    osdAttr.stContent.u32Color = 0xffE0;
    osdAttr.stContent.stStrContent.stFontSize.u32Width = 30;
    osdAttr.stContent.stStrContent.stFontSize.u32Height = 60;
    osdAttr.stContent.stStrContent.u32BgColor = 0xccc;
    snprintf(osdAttr.stContent.stStrContent.szStr, HI_MAPI_OSD_MAX_STR_LEN, textContent.m_text.c_str());

    ret = HI_MAPI_OSD_SetAttr(osdHdl, &osdAttr);
    if(ret != HI_SUCCESS)
    {
        printf("HI_MAPI_OSD_SetAttr failed, osdHdl:%d \n", osdHdl);
        return ret;
    }

    ret = HI_MAPI_OSD_Start(osdHdl);
    if(ret != HI_SUCCESS)
    {
        printf("HI_MAPI_OSD_Start failed, osdHdl:%d \n", osdHdl);
        return ret;
    }
    return HI_SUCCESS;

}

HI_S32 HiDraw::StopDraw(HI_HANDLE osdHdl)
{
    HI_S32 ret = HI_MAPI_OSD_Stop(osdHdl);
    if(ret != HI_SUCCESS)
    {
        printf("stop  osd %u failed\n", osdHdl);
        return ret;
    }

    return HI_SUCCESS;
}


